<?php

/**
 * m120805_131754_user_table_migration.php
 *
 * @author: Hemendra <hemendra@t9l.com>
 * 
 */
class m120805_131754_user_table_migration extends CDbMigration {

    public function up() {
        $this->execute("CREATE TABLE IF NOT EXISTS `tbl_backend_user` (
                            `id` int(11) NOT NULL AUTO_INCREMENT,
                            `username` varchar(45) DEFAULT NULL,
                            `password` varchar(255) DEFAULT NULL,
                            `salt` varchar(255) DEFAULT NULL,
                            `password_strategy` varchar(50) DEFAULT NULL,
                            `requires_new_password` tinyint(1) DEFAULT NULL,
                            `email` varchar(255) DEFAULT NULL,
                            `login_attempts` int(11) DEFAULT NULL,
                            `login_time` int(11) DEFAULT NULL,
                            `login_ip` varchar(32) DEFAULT NULL,
                            `validation_key` varchar(255) DEFAULT NULL,
                            `create_time` int(11) DEFAULT NULL,
                            `update_time` int(11) DEFAULT NULL,
                            `status` tinyint(1) NOT NULL DEFAULT '0',
                            PRIMARY KEY (`id`),
                            UNIQUE KEY `username` (`username`),
                            UNIQUE KEY `email` (`email`)
                          ) ENGINE=InnoDB  DEFAULT CHARSET=utf8");


        
        /* add admin user to backend*/
        /*username and email are diffrent . user can login by email or useranme*/
        $adminUser = new BackendUser();
        $adminUser->username = "admin";
        $adminUser->email = "admin@t9l.com";
        $adminUser->password = "admint9l";

        $adminUser->insert();
    }

    public function down() {
        $this->dropTable('tbl_backend_user');
     
    }

}